<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>主要备件列表</title>
		<!-- css代码 start -->
		<link href="../../../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../../../css/global.css" rel="stylesheet" />
		<link href="../../../../../css/style.css" rel="stylesheet" />
		<link href="../../../../../css/task.css" rel="stylesheet" />
		<style>
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 65%;
				left: 50%;
			}
			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			.item_box .item .name{
				font-weight: inherit;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>
		<!-- html代码 start -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">主要备件列表</h1>
		</header>
		<div class="mui-content">
			<div hidden>
				<input type="hidden" id="ServiceNoticeId" />
				<input type="hidden" id="instrumentNo" />
				<input type="hidden" id="serviceNoV" />
			</div>
			<div id="div"></div>
			<div id="popover" class="mui-popover shadow popover">
				<p class="title">确定要删除吗?</p>
				<div class="btn_box">
					
					<span class="fl" onclick="closepop()">取消</span>
					<span class="fr red" id="queding">确定</span>
				</div>
			</div>
			<div class="item_box" id="liebiao">

				<!-- <div class="item" >
					<p class="bar"><span class="number">1170001<img src="../../../../../images/icon_3.png" /></span><span class="del">删除</span></p>
					<div class="text">附件名称<span>121212</span></div>
					<div class="text">附件序列号<span>2312323</span></div>
					<div class="text">保修开始时间<span>23424234</span></div>
					<div class="text">保修结束时间<span>23424234</span></div>
				</div>
				<div class="item" >
					<p class="bar"><span class="number">1170001<img src="../../../../../images/icon_3.png" /></span><span class="del">删除</span></p>
					<div class="text">附件名称<span>121212</span></div>
					<div class="text">附件序列号<span>2312323</span></div>
					<div class="text">保修开始时间<span>23424234</span></div>
					<div class="text">保修结束时间<span>23424234</span></div>
				</div> -->
			</div>
			<div class="btn_box">
				<span id="tjzybj" class="fl red one">添加主要备件</span>
			</div>
			<div style="height: 50px;"></div>
		</div>
		<!-- html代码 end -->

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../../js/mui.min.js"></script>
		<script src="../../../../../js/utils/h.js"></script>
		<script src="../../../../../js/constant.js"></script>
		<script src="../../../../../js/common.js"></script>
		<script src="../../../../../js/utils/base64.js"></script>
		<script src="../../../../../js/utils/md5.js"></script>
		<script src="../../../../../js/utils/sortMap.js"></script>
		<script src="../../../../../js/utils/http.js"></script>
		<script src="../../../../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			var id;
			// 提交状态 0未提交 1已提交
			var submitStatus = 0;
			(function($, doc) {
				$.init();

				$.plusReady(function() {
					var self = plus.webview.currentWebview();
					submitStatus = self.submitStatus
					if (submitStatus && submitStatus == '1') {
						h('#tjzybj').hide()
					}
					// 获取上一个页面传过来的参数并显示到页面
					h('#serviceNoV').val(self.serviceNo);
					h('#ServiceNoticeId').val(self.ServiceNoticeId);
					h('#instrumentNo').val(self.instrumentNo);
					initData()

					//添加备件
					h("#tjzybj").tap(function(){
						app.jumpTo("/view/service/report/installationquality/mainSpareParts/add.html","view/service/report/installationquality/mainSpareParts/add.html",
								{
									ServiceNoticeId: h("#ServiceNoticeId").val(),
									serviceNo: h("#serviceNoV").val(),
									instrumentNo: h("#instrumentNo").val(),
									addType:1
								})
					})
					// 确定删除
					h("#queding").tap(function() {
						mui("#popover").popover('toggle', document.getElementById("div"));
						app.showWaiting('删除中...')
						ajaxGet(BASE_URL + "cc/installation/quality/report/removeMajorPart", {
							"instrumentNo": h("#instrumentNo").val(),
							"enginnerId": app.getUser().enginnerId,
							"serviceNo": h("#serviceNoV").val(),
							"partsId": id
						}, function(data) {
							app.closeWaiting()
							console.log(JSON.stringify(data))
							if (data.code == 200) {
								app.toast("删除成功")
						
							} else {
								app.toast("删除失败")
							}
							initData()
							
						}, function(errorMsg) {
							app.closeWaiting()
							console.log(JSON.stringify(errorMsg))
							app.toast(JSON.stringify(errorMsg))
						});

					})

				});
			}(mui, document));
			// 列表查询
			function initData() {
				console.log(h("#instrumentNo").val())
				ajaxGet(BASE_URL + "cc/installation/quality/report/selectMajorParts", {
					"instrumentNo": h("#instrumentNo").val(),
					"enginnerId": app.getUser().enginnerId,
					"serviceNo": h("#serviceNoV").val()
				}, function(data) {
					console.log(JSON.stringify(data))
					if (data.code == 200) {
						h("#liebiao").html("");
						var html = "";
						if (data.data != "") {
							for (var i = 0; i < data.data.length; i++) {
								var das = data.data[i];
								var Parts_ID = das.Parts_ID == undefined ? "无" : das.Parts_ID;
								var Parts_Code = das.Parts_Code == undefined ? "无" : das.Parts_Code;
								var Parts_Name = das.Parts_Name == undefined||das.Parts_Name == "" ? "无" : das.Parts_Name;
								var Parts_Serial = das.Parts_Serial == undefined ? "无" : das.Parts_Serial;
								var Parts_WarrantyStart = das.Parts_WarrantyStart == undefined ? "无" : das.Parts_WarrantyStart;
								var Parts_WarrantyEnd = das.Parts_WarrantyEnd == undefined ? "无" : das.Parts_WarrantyEnd;
								html += '<div class="item" >'
								html += '<p class="bar"><span class="number">' + Parts_Code +
									'<img src="../../../../../images/icon_204.png" /></span><span class="del" onclick=shanchu(\'' + Parts_ID +
									'\')>删除</span></p>'
								html += '<div class="name">备件名称：<span>' + Parts_Name + '</span></div>'
								html += '<div class="name">备件序列号：<span>' + Parts_Serial + '</span></div>'
								html += '<div class="name">保修开始时间：<span>' + Parts_WarrantyStart + '</span></div>'
								html += '<div class="name">保修结束时间：<span>' + Parts_WarrantyEnd + '</span></div>'
								html += '</div>';
							}
							h("#liebiao").html(html);
							if (submitStatus == '1') {
								h('.del').hide()
							}
						} else {
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#liebiao").html(html);
						}
					} else {
						var html = '<div class="nodata">—— 暂无数据 ——</div>';
						h("#liebiao").html(html);
					}
				}, function(errorMsg) {
					console.log(JSON.stringify(errorMsg))
				});
			}

			// 删除方法
			function shanchu(Parts_ID) {
				id = Parts_ID;
				mui("#popover").popover('toggle', document.getElementById("div"));
			}

			// 取消删除
			function closepop() {
				mui("#popover").popover('toggle', document.getElementById("div"));
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>
